package com.codeZ.MementoPattern.instance;

import lombok.Data;

/**
 * 游戏角色
 *
 * @author codeZhang
 * @Date 2024/8/30 14:12
 */
@Data
public class GameRole {


    /**
     * 生命值
     */
    private int vitality;

    /**
     * 攻击力
     */
    private int attack;

    /**
     * 防御力
     */
    private int defense;

    // 保存角色状态
    public RoleStateMemento saveState() {
        return new RoleStateMemento(vitality, attack, defense);
    }

    // 恢复角色状态
    public void recoverState(RoleStateMemento memento) {
        this.vitality = memento.getVitality();
        this.attack = memento.getAttack();
        this.defense = memento.getDefense();
        System.out.println("恢复角色状态成功！");
        display();
    }

    public void display() {
        System.out.println("角色当前状态：");
        System.out.println("生命值：" + vitality);
        System.out.println("攻击力：" + attack);
        System.out.println("防御力：" + defense);
    }

    public void initState() {
        this.vitality = 100;
        this.attack = 100;
        this.defense = 100;
        display();
    }

    public void fight() {
        this.vitality = 0;
        this.attack = 0;
        this.defense = 0;
        display();
    }


}
